// pages/course/tutorial/tutorial.js
var util = require("../../utils/util.js");

Page({

  /**
   * 页面的初始数据
   */
  data: {
    CurrList: [],
    sorts: ["综合排序", "销量排序", "价格从高到低", "价格从低到高"],
    params: {
      Param: { ParentLabelID: 0, LabelID: 0, Difficulty: 0, PageIndex: 1, ShowIndexNum: 20, SortType: 0, PriceType: 0 },
      Action: 4808
    },
    params2: {
      Param: {
        SearchKey: "",
        InPackeage: 0,
        InLive: 0,
        InEduVideo: 0,
        InEduVoice: 0,
        InCurr: 1,
        PageIndex: 1,
        ShowIndexNum: 20
      },
      Action: 18900
    },
    srHidden: true,
  },


  //component-select
  onShowResult: function () {
    var that = this;
    var params2 = this.data.params2;
    params2.Param.SearchKey = this.selectComponent('#select').onGetSearchKey();
    util.reqMedia(params2, function (value) {
      that.setData({
        CurrList: value.CurrList
      });
    });
    this.setData({
      srHidden: false,
      tlHidden: true
    });

  },
  onPickerChange: function () {
    var index = this.selectComponent('#select').onGetIndex();
    var params = this.data.params;
    params.Param.SortType = index;
    var page = this;
    util.reqMedia(params, function (value) {
      page.setData({
        CurrList: value.CourseInfoList
      });
    });
    this.setData({
      srHidden: true,
      tlHidden: false
    });
  },
  onConfirm: function () {
    var accordion = this.selectComponent('#select').onGetAccordion();
    var params = this.data.params;
    params.Param.Difficulty = accordion.AdaptationType;
    params.Param.PriceType = accordion.PriceType;
    params.Param.ParentLabelID = accordion.ParentLabelID;
    params.Param.LabelID = accordion.LabelID;
    var page = this;
 
    util.reqMedia(params, function (value) {
      console.log(value);
      page.setData({
        CurrList: value.CourseInfoList
      });
    });
    this.setData({
      srHidden: true,
      tlHidden: false
    });
  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var params = this.data.params;

    util.reqMedia(params, function (value) {
      that.setData({
        CurrList: value.CourseInfoList
      });
    });

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.showLoading({
      title: 'loading'
    });
    setTimeout(function () {
      wx.hideLoading();
      wx.stopPullDownRefresh();
    }, 1000);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    wx.showLoading({
      title: '到底了',
    });
    setTimeout(function () {
      wx.hideLoading();
    }, 1000);

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})